<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="format-detection" content="telephone=no" />
    <meta name="format-detection" content="email=no" />
    <title>首页</title>
    <link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.9.3/skins/default/aliplayer-min.css" />
    <link rel="stylesheet" href="../../css/api.css">
    <link rel="stylesheet" href="../../css/swiper.min.css">
    <link rel="stylesheet" href="../../css/choumei.min.css">
    <link rel="stylesheet" href="../../css/vant.css">
    <link rel="stylesheet" href="../../css/main.css">
    <style>
        .app {
            background: #fff;
        }

        .info img,
        .kf img {
            width: .22rem;
            height: .22rem;
            object-fit: fill;
        }

        .home-head .head .info {
            position: relative;
        }

        .home-head .head .info.redDot::after {
            content: ' ';
            background: #F53B31;
            position: absolute;
            top: -.035rem;
            right: -.035rem;
            border-radius: 50%;
            width: .07rem;
            height: .07rem;
        }

        .homePage {
            /* width: 100vw;
            height: .12rem; */
            /* background: #F5F5F5; */
        }

        .recom-text>.title {
            width: 1.6rem;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
    </style>
</head>

<body>
    <div class="app homePage" v-cloak>

        <!--顶部搜索 bannber 八个icon-->
        <div class="home-top">
            <!--顶部搜索-->
            <div class="home-search">
                <div class="home-head" id="home-head">
                    <div class="head flex-x-sb">
                        <div class="area flex-x-sb" @click="goRelative('area_select_win', '../select/')">
                            <div>{{selectedCityName}}</div>
                            <img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_city_right_ico.png" alt="" width="10" height="6">
                        </div>
                        <div class="head-search" @click="goHeadPage('search')">
                            <img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_head_search_ico.png" width="13" height="13" alt="">
                            <span class="text-placeholder">请搜索关键字</span>
                        </div>
                        <div @click="goHeadPage('info')" class="head-message">
                            <div class="count" v-if="unReadNum > 0">{{unReadNum}}</div>
                            <img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/info.png" width="20" height="20" alt="">
                        </div>
                        <div @click="gIMCommon('')">
                            <img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/kf.png" alt="" width="18" height="20" style="margin-top: 0.02rem;">
                        </div>
                    </div>
                </div>
            </div>
            <!--banner-->
            <div class="home-banner">
                <van-swipe class="my-swipe" :loop="false" indicator-color="white" :stop-propagation="false">
                    <van-swipe-item v-for="(banner,index) in banners" :key="index" @click="goWeb(banner)">
                        <img v-if="!banner.playURL" :src="banner.imageUrl" class="home-banner-img">
                        <div v-else>
                            <div class="videoPlay home-banner-img">
                                <video :id="'player'+index" class="home-banner-img" height="100rem" controls="true"
                                    preload="none" webkit-playsinline="true" playsinline="true"
                                    :poster="banner.imageUrl" x5-playsinline>
                                    <source :src="banner.playURL" type="video/mp4" />
                                </video>
                            </div>
                        </div>
                    </van-swipe-item>
                </van-swipe>
            </div>
            <!-- 八个icon -->
            <div class="home-menu">
                <div class="e-icon">
                    <div class="f-icon">
                        <div v-for="(item, index) in iconList" :key="index" class="single-icon"
                            @click="goPage(item.url, {title: item.name})">
                            <img :src="item.img" alt="" width="35" height="35">
                            <div>{{item.name}}</div>
                        </div>
                    </div>
                    <div class="f-icon">
                        <div v-for="(item, index) in iconList1" :key="index" class="single-icon"
                            @click="goPage(item.url, {title: item.name})">
                            <img :src="item.img" alt="" width="35" height="35">
                            <div>{{item.name}}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--头条-->
        <div class="headline" @click="goHeadLine">
            <div class="left">
                <img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/headline.png" alt="" width="29.5" height="12.5">
                <div class="title" v-if="headLineList.length>0">{{headLineList[0].title}}</div>
            </div>
            <!-- 
            <marquee class="title" direction="left" behavior="scroll" loop="1">
                美国巨型冲击锤在德州正式投入使用s踏破芒鞋 烟雨任平生,慧行坚勇 究畅恒无极
            </marquee> -->
            <div class="golook">去看看</div>
        </div>
        <!--精选功能-->
        <div class="selection-function">
            <div class="selection-function-top">
                <div class="selection-function-top-title">精选功能</div>
                <div class="selection-function-top-content">
                    <div><img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_all_right.png" width="10" height="10" alt=""> 特色服务</div>
                    <div><img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_all_right.png" width="10" height="10" alt=""> 专业保障</div>
                    <div><img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_all_right.png" width="10" height="10" alt=""> 方便快捷</div>
                </div>
            </div>
            <div class="selection-function-bottom">
                <div class="selection-function-bottom-item" @click="goVideoDetail(goodVideo.topicId,1)">
                    <div class="selection-function-bottom-item-top">
                        <div class="title">精彩视频</div>
                        <img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_hot_ico.png" width="27" height="19" alt="">
                    </div>
                    <div class="content">深入多种场景</div>
                    <img class="imgDes" src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_video_ico.png" width="52" height="60" alt="">
                </div>
                <div class="selection-function-bottom-item" @click="showCallPhonePop = true">
                    <div class="title">我要咨询</div>
                    <div class="content">客户专属服务</div>
                    <img class="imgDes imgService" src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_service_ico.png" width="91" height="54"
                        alt="">
                </div>
            </div>
        </div>
        <!-- 资讯 -->
        <div class="news">
            <div class="title">
                <img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/news_icon.png" width="17" height="19" alt="">
                <span>最新资讯</span>
            </div>
            <div class="news-item" v-for="(item,index) in listNews" :key="index" @click="goNewsDetail(item)">
                <div class="left">
                    <div class="new-title">{{item.title}}</div>
                    <div class="time">{{handleTimeYMD2(item.createTime)}}</div>
                </div>
                <div class="right"  v-if="item.coverPicture">
                    <img v-lazy="item.coverPicture?item.coverPicture:'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/default/loading3.png'" alt=""
                        width="100" height="80" style="border-radius: 0.04rem;">
                </div>
            </div>
        </div>

        <!--推荐 -->
        <div class="recommend" v-show="false">
            <van-tabs v-model="active" line-height="0px" swipeable @change="recommendChange" animated sticky
                :offset-top="headerH">
                <van-tab v-for="(item,index) in recommendCategoryList" :key="index">
                    <div slot="title" class="my-tab-title-content">
                        <div class="my-tab-title">
                            <div>{{item.typeStr}}</div>
                            <div :class="index === active?'des-selected':'des'">{{item.typeDes}}</div>
                        </div>
                        <div class="right-line" v-show="index!=recommendCategoryList.length-1"></div>
                    </div>

                    <div class="home-recommend" :key="active">
                        <div class="home-recommend-empty" v-if="listNew.length==0">
                            暂无相关数据
                        </div>
                        <div class="home-recommend-goods-item" v-for="(item,index) in listNew" :key="index"
                            @click="goDetail(item)">
                            <img class="goods-pic"
                                v-lazy="item.imageUrl ? item.imageUrl : 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/default/loading3.png'"
                                :key="item.imageUrl" alt="">
                            <div class="title">{{item.title}}</div>
                            <div class="price"> <span style="margin: 0;"
                                    v-if="item.price<10000 && item.price!==null">¥</span>
                                <span>{{item.price | filterPrice}}</span>
                            </div>
                        </div>
                    </div>

                </van-tab>
            </van-tabs>
        </div>

        <!-- 电话咨询 在线客服 -->
        <van-popup v-model="showPh" closeable round :style="{ height: '30%',width:'90%' }" class="flex-x-c">
            <div class="home-contact-info">
                <div>请选择联系方式</div>
                <div class="home-contact-btn flex-x-sb">
                    <div>电话咨询</div>
                    <div>在线客服</div>
                </div>
            </div>
        </van-popup>

        <!-- 版本更新弹窗 -->
        <van-popup v-model="showUpdatePop" :style="{ height: 'auto',width:'80%' }" class="my-update-pop">
            <div class="update-top">
                <div class="title">发现新版本</div>
                <div class="version"><span>v{{newVersionCode}}</span> </div>
                <div class="content-title flex-x-c">感谢您对铁蟹网的支持，本期更新功能为：</div>
                <!-- {{updateContent}} -->
                <div class="content"> {{updateContent}} </div>
                <div class="submit flex-x-c" @click="update">立即升级</div>
                <div class="login-privacy flex-x-c" @click="setNotice(1)">
                    <img :src="showImgNotice?'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_update_notice_select.png':'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_update_notice_normal.png'"
                        alt="">
                    不再提示
                </div>
                <div v-if="downLoadPercent!=0" class="download-progress">
                    <van-progress :percentage="downLoadPercent" />
                </div>

            </div>
            <div class="update-bottom">
                <img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/update_close.png" alt="" class="flex-x-c" width="40" height="40"
                    @click="showUpdatePop=false">
            </div>
        </van-popup>

        <!-- 马达促销活动弹窗 -->
        <van-popup v-model="showDiscountPop" :style="{ height: 'auto',width:'80%' }" class="my-discount-pop">
            <div class="discount-top">
                <img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_discount_bg.png" alt="" width="100%" height="auto">
                <div class="discount-btn">
                    <div class="submit flex-x-c" @click="goDiscountDetail()">立即前往</div>
                    <div class="login-privacy flex-x-c" @click="setNotice(2)">
                        <img :src="showDiscountImgNotice?'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_discount_notice_select.png':'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_discount_notice_normal.png'"
                            alt="">
                        不再提示
                    </div>
                </div>
            </div>

            <div class="update-bottom">
                <img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/update_close.png" alt="" class="flex-x-c" width="40" height="40"
                    @click="showDiscountPop=false">
            </div>
        </van-popup>

        <!-- 全民经纪人弹窗 -->
        <van-popup v-model="showWalletPop" :style="{ height: 'auto',width:'88%' }" class="my-discount-pop">
            <div class="discount-top">
                <img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_wallet.png" alt="" width="100%" height="auto" @click="goWalletDetail()">
                <div class="discount-btn wallet-notice">
                    <div class="login-privacy flex-x-c " @click="setNotice(3)">
                        <img :src="showWalletImgNotice?'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_discount_notice_select.png':'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_discount_notice_normal.png'"
                            alt="">
                        不再提示
                    </div>
                </div>
            </div>

            <div class="update-bottom">
                <img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/update_close.png" alt="" class="flex-x-c" width="40" height="40"
                    @click="showWalletPop=false">
            </div>
        </van-popup>

        <!-- 我要咨询弹窗 -->
        <van-popup v-model="showCallPhonePop" :style="{ height: 'auto',width:'80%' }" class="home-callphone-pop">
            <div class="top">
                确认拨打电话 <span>400-777-3220</span> 吗？
            </div>
            <div class="bottom">
                <button class="confirm" @click="callPhone()">确认</button>
                <button class="cancel" @click="showCallPhonePop = false">取消</button>
            </div>
        </van-popup>

        <!-- 未登录弹窗 -->
        <van-popup v-model="showNologinPop" :style="{ height: 'auto',width:'80%' }" class="home-no-login-pop">
            <div class="top">
                温馨提示
                <img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/circle/circle_comment_close_ico.png" alt="" width="14" height="14"
                    @click="showNologinPop=false">
            </div>
            <div class="content">
                您还未登录，无法参与视频达人领现金活动！建议您立即登录~
            </div>
            <div class="btn-container">
                <button class="continue" @click="continueLook()">继续观看</button>
                <button class="confirm" @click="goLogin()">去登录</button>
            </div>
        </van-popup>

        <!-- 看视频领红包 -->
        <div class="home-video-pop" v-if="showVideoPop">
            <img class="close" @click="showVideoPop = false" src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_video_close_icon.png" width="20"
                height="20" alt="">
            <img @click="goVideoIntro()" src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/home_video_icon.png" height="91" width="85" alt="">
        </div>
    </div>
    <script type="text/javascript" charset="utf-8" src="https://g.alicdn.com/de/prismplayer/2.9.3/aliplayer-min.js">
    </script>
    <script src="../../script/api.js"></script>
    <script src="../../script/flexible.js"></script>
    <script src="../../script/fastclick.js"></script>
    <script src="../../script/vue.min.js"></script>
    <script src="../../script/iconfont.js"></script>
    <script src="../../script/restful.js"></script>
    <script src="../../script/common.js"></script>
    <script src="../../script/swiper.min.js"></script>
    <script src="../../script/vant.min.js"></script>
    <script src="../../script/businessCommon.js"></script>
    <script src="../../script/vue-lazyload.js"></script>
    <script>
        //监听页面滚动
        window.onscroll = function () {
            var t = document.documentElement.scrollTop || document.body.scrollTop;
            var top_div = document.getElementById("home-head");
            if (t >= 120) {
                top_div.style.backgroundColor = "#000000";
                top_div.style.opacity = "0.7";
            } else {
                top_div.style.backgroundColor = "transparent";
                top_div.style.opacity = "1";
            }
        }
        apiready = function () {
            var aMap = api.require('aMap');
            imgLazyLoad();
            var vm = new Vue({
                el: '.app',
                data: {
                    newsList: [{}, {}, {}, {}, {}],//新闻列表
                    showVideoPop: false,//看视频 领红包弹窗
                    showCallPhonePop: false,//我要咨询弹窗
                    showDiscountPop: false,//促销弹窗
                    showWalletPop: false,//全民经纪人弹窗
                    showWalletImgNotice: false,//促销不再提示
                    showDiscountImgNotice: false,//促销不再提示
                    showNologinPop: false,//未登录弹窗提示
                    active: 0,
                    recommendCategoryList: [{
                        typeStr: '精选',
                        typeDes: '为您推荐',
                        types: []

                    }, {
                        typeStr: '整机',
                        typeDes: '在线询价',
                        types: [0]
                    }, {
                        typeStr: '出租',
                        typeDes: '海量设备',
                        types: [1]
                    }, {
                        typeStr: '配件',
                        typeDes: '原装正品',
                        types: [2]
                    }],
                    frames: [],
                    headerH: 0,
                    selectedCityName: "上海市",
                    kfUrl: '',
                    unReadNum: 0,
                    queryHeadLine: {
                        pageNum: 1,
                        pageSize: 10,
                        status: 1,
                    },
                    headLineList: [],
                    goodVideo: {},

                    showPh: false,
                    iconList: [{
                        img: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/zjmm.png',
                        name: '整机买卖',
                        url: 'whole_sale'
                    }, {
                        img: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/zncz.png',
                        name: '租赁出租',
                        url: 'whole_sale'
                    }, {
                        img: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/gxgxs.png',
                        name: '二手材料',
                        url: 'deformed_steel'
                    }, {
                        img: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/pjsc.png',
                        name: '配件商城',
                        url: 'whole_sale'
                    }],
                    iconList1: [{
                        img: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/wxby.png',
                        name: '维修保养',
                        url: 'maintenance'
                    }, {
                        img: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/ygzp.png',
                        name: '用工招聘',
                        url: 'recruit'
                    }, {
                        img: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/sffw.png',
                        name: '行业资讯',
                        url: 'industry_news'
                    }, {
                        img: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/home/ccwl.png',
                        name: '物流运输',
                        url: 'warehouse_logistics'
                    }],
                    banners: [],
                    videoShow: null, // topicId1 右上   topicId2 右下  topicIdMain左
                    listNew: [],
                    queryParams: {
                        types: '',
                        pageNum: 1,
                        pageSize: 10,
                        status: 1,
                        checkStatus: 1,
                        recommended: true
                    },
                    hasNext: true,
                    isRefresh: false,
                    appVersionUpdate: false,//是否显示ios版本更新弹窗
                    androidDownloadUrl: 'https://cdn.tiexiemall.com/static/apk/tiexie.apk',//安卓下载地址
                    updateContent: '',//更新文案
                    showImgNotice: null,//不再提示
                    showUpdatePop: false,//版本更新弹窗
                    newVersionCode: '',//最新版本号
                    downLoadPercent: 0,//下载进度
                    //视频秀
                    findRecommend: {
                        leftUrl: 'https://cdn.tiexiemall.com/static/tiexie/image/left.jpg',
                        rightTopUrl: 'https://cdn.tiexiemall.com/static/tiexie/gif/right_up.gif',
                        rightBottomUrl: 'https://cdn.tiexiemall.com/static/tiexie/gif/right_down.gif'
                    },
                    listNews: [], // 最新资讯
                    newsForm: {
                        pageNum: 1,
                        pageSize: 3
                    },
                },
                filters: {
                    filterPrice: filterPrice
                },
                mounted() {
                    this.getUnReadNum()
                    this.initData();
                    // this.getNew();
                    this.getSystemSet();
                    this.getHeadLineData();
                    this.getRecommendVideo();
                    this.calculateHeadHeight();
                    this.getNewsData()
                    //控制马达活动的弹窗显示与否
                    // var isNoNoticFlag = $api.getStorage('noNoticeDiscount')
                    // this.showDiscountPop = !isNoNoticFlag
                },
                methods: {
                    // 跳转到详情页
                    goNewsDetail(item) {
                        api.openWin({
                            name: 'industry_news_detail_win',
                            url: '../industry_news/industry_news_detail_win.html',
                            bounces: false,
                            pageParam: {
                                id: item.id,
                            }
                        });
                    },
                    // 资讯列表
                    getNewsData() {
                        let vm = this
                        index.news("getListNews")(vm.newsForm, (ret) => {
                            vm.listNews = ret.data
                            if (vm.newsForm.pageNum == 1) {
                                vm.listNews = ret.data.list
                            } else {
                                vm.listNews = vm.listNews.concat(ret.data.list)
                            }
                            vm.hasNext = ret.data.hasNext
                        })
                    },

                    initLocation(url, options) {
                        var vm = this;
                        var aMap = api.require('aMap');
                        aMap.open({
                            rect: { x: 0, y: 0, w: 0, h: 0 },
                            showUserLocation: true,
                            zoomLevel: 11,
                            center: { lon: 116.4021310000, lat: 39.9994480000 },
                            fixedOn: api.frameName,
                            fixed: true
                        }, function (ret, err) {
                            if (ret.status) {
                                // 获取经纬度
                                aMap.getLocation(function (ret1, err1) {
                                    if (ret1.status) {
                                        // 根据经纬度获取城市
                                        aMap.getNameFromCoords({ lon: ret1.lon, lat: ret1.lat }, (ret2, err2) => {
                                            if (ret2.status && ret2.address) {
                                                vm.selectedCityName = ret2.state

                                                if (ret2.citycode) {
                                                    index.area('getProvinceByCityCode')(ret2.citycode, function (ret) {
                                                        var location = {
                                                            name: ret2.state,
                                                            location: ret1.lon + "," + ret1.lat,
                                                        }
                                                        if (ret && ret.data) {
                                                            location.id = ret.data.id
                                                        }
                                                        $api.setStorage('location_home', location);
                                                        api.setPrefs({
                                                            key: 'location_home',
                                                            value: location
                                                        });
                                                        api.openWin({
                                                            name: url + '_win',
                                                            url: `../${url}/${url}_win.html`,
                                                            bounces: false,
                                                            pageParam: (options || {})
                                                        });
                                                        // setTimeout(() => {
                                                        //     console.log("定位发111111111" + JSON.stringify(location))
                                                        //     api.sendEvent({
                                                        //         name: 'showLocation',
                                                        //         extra: { cityName: location.name }
                                                        //     })
                                                        // }, 2000);

                                                    })
                                                }
                                            } else {
                                                vm.selectedCityName = '上海市'
                                                var location = {
                                                    name: '上海市',
                                                    location: '121.164311' + ',' + '31.046996',
                                                    id: 10796 // 上海市id为10796，从后端开发人员获取到
                                                }
                                                $api.setStorage('location_home', location);
                                                api.setPrefs({
                                                    key: 'location_home',
                                                    value: location
                                                });
                                                api.openWin({
                                                    name: url + '_win',
                                                    url: `../${url}/${url}_win.html`,
                                                    bounces: false,
                                                    pageParam: (options || {})
                                                });
                                                // setTimeout(() => {
                                                //     api.sendEvent({
                                                //         name: 'showLocation',
                                                //         extra: { cityName: location.name }
                                                //     })
                                                // }, 2000);
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    },
                    checkLocation(url, options) {
                        var vm = this
                        var resultList = api.hasPermission({
                            list: ['location']
                        });
                        var isPermit = resultList[0].granted;
                        if (isPermit) {
                            // 获取定位信息
                            vm.initLocation(url, options)
                        } else {
                            // 没有权限 请求权限
                            if ($api.getStorage('isLocationPerm') == 1) {
                                api.openWin({
                                    name: url + '_win',
                                    url: `../${url}/${url}_win.html`,
                                    bounces: false,
                                    pageParam: (options || {})
                                });
                            } else {
                                api.requestPermission({
                                    list: ['location'],
                                }, function (ret, err) {
                                    if (ret.list[0].granted) {
                                        // 获取定位信息
                                        vm.initLocation(url, options)
                                    } else {
                                        api.openWin({
                                            name: url + '_win',
                                            url: `../${url}/${url}_win.html`,
                                            bounces: false,
                                            pageParam: (options || {})
                                        });
                                        $api.setStorage('isLocationPerm', '1');
                                        api.setPrefs({
                                            key: 'isLocationPerm',
                                            value: 1
                                        });
                                    }
                                });
                            }
                        }
                    },

                    //跳转到视频达人介绍
                    goVideoIntro() {

                    },
                    //继续观看
                    continueLook() {
                        let vm = this
                        //记录点击的当前时间 保存
                        var data = new Date()
                        var continueTime = data.getTime()

                        $api.setStorage('continueTime', continueTime)
                        api.setPrefs({
                            key: 'continueTime',
                            value: continueTime
                        });
                        vm.showNologinPop = false

                        //跳转到视频页
                        vm.goVideo()
                    },
                    //去登录
                    goLogin() {
                        this.showNologinPop = false
                        api.openWin({
                            name: 'login_win',
                            url: 'widget://html/login/login_win.html',
                            slidBackEnabled: true,
                            bounces: false,
                            reload: true,
                            pageParam: { key: 'value' }
                        });
                    },
                    //我要咨询拨打电话
                    callPhone() {
                        api.call({
                            type: 'call_type',
                            number: '4007773220'
                        });
                        this.showCallPhonePop = false
                    },

                    //跳转到全民经纪人活动详情
                    goWalletDetail() {
                        if (!checkHomeToken()) return false;

                        this.showWalletPop = false
                        api.openWin({
                            name: 'invite_friend_win',
                            url: '../mine/invite_friend_win.html',
                        });
                    },
                    //跳转到马达活动详情
                    goDiscountDetail() {
                        this.showDiscountPop = false
                        api.openWin({
                            name: 'web_win',
                            url: '../web/web_win.html',
                            bounces: false,
                            pageParam: {
                                url: ''
                            }
                        });
                    },
                    // 计算header高度
                    calculateHeadHeight() {
                        var vm = this;
                        vm.$nextTick(() => {
                            var header = $api.dom('.home-search');
                            if (api.systemType == "ios") {
                                vm.headerH = $api.fixStatusBar(header) - 6;
                            } else {
                                vm.headerH = $api.fixStatusBar(header);
                            }
                        })
                    },

                    goHeadPage(url) {
                        let vm = this
                        api.openWin({
                            name: url + '_win',
                            url: `../${url}/${url}_win.html`,
                            bounces: false,
                            pageParam: {
                                key: 'value',
                                kfUrl: vm.kfUrl,
                                titlePlus: '首页'
                            }
                        });
                    },
                    goRelative(url, relative) {
                        api.openWin({
                            name: url,
                            url: (relative || '') + url + ".html",
                            bounces: false,
                            pageParam: { title: 'home' }
                        })
                    },
                    //获取未读消息数量
                    getUnReadNum() {
                        //var token = $api.getStorage('accessToken')
                        var token = api.getPrefs({
                            sync: true,
                            key: 'accessToken'
                        });
                        if (token) {
                            let vm = this
                            common('getUnReadNum')(function (ret) {
                                vm.unReadNum = ret.data
                                if (vm.unReadNum > 99) {
                                    vm.unReadNum = 99
                                }
                            })
                        }
                    },

                    //视频秀跳转到视频播放页面
                    goVideoDetail(topicId, type) {
                        var vm = this
                        if (type === 0) {
                            api.openWin({
                                name: 'circle_pic_detail',
                                url: '../circle_new/circle_pic_detail.html',
                                bounces: false,
                                pageParam: {
                                    topicId: topicId,
                                    screenType: 0,
                                    channelId: null,
                                }
                            });
                        } else {
                            //var token = $api.getStorage('accessToken')
                            var token = api.getPrefs({
                                sync: true,
                                key: 'accessToken'
                            });
                            //var continueTime = $api.getStorage('continueTime')
                            var continueTime = api.getPrefs({
                                sync: true,
                                key: 'continueTime'
                            });
                            var data = new Date()
                            var currentTime = data.getTime()

                            if (token || (currentTime - continueTime <= 12 * 60 * 60 * 1000)) {
                                vm.goVideo()
                            } else {
                                //大于12小时则弹出提示框,或首次未登录
                                vm.showNologinPop = true
                            }
                        }
                    },

                    goVideo() {
                        api.openWin({
                            name: 'circle_video_detail',
                            url: '../circle_new/circle_video_detail.html',
                            bounces: false,
                            pageParam: {
                                topicId: vm.goodVideo.topicId,
                                screenType: 0,
                                channelId: null,
                            }
                        });
                    },

                    //升级弹窗的不在提示
                    setNotice(type) {
                        switch (type) {
                            case 1://升级弹窗
                                this.showImgNotice = !this.showImgNotice
                                if (vm.showImgNotice) {
                                    //保存不在提示的版本号
                                    $api.setStorage('noNoticeVersion', this.newVersionCode);

                                } else {
                                    $api.setStorage('noNoticeVersion', '');

                                }
                                break
                            case 2://促销弹窗
                                this.showDiscountImgNotice = !this.showDiscountImgNotice
                                if (vm.showDiscountImgNotice) {
                                    //保存不在提示
                                    $api.setStorage('noNoticeDiscount', true);
                                } else {
                                    $api.setStorage('noNoticeDiscount', false);
                                }
                                break
                            case 3://全民经纪人弹窗
                                this.showWalletImgNotice = !this.showWalletImgNotice
                                if (vm.showWalletImgNotice) {
                                    //保存不在提示
                                    $api.setStorage('noNoticeWallet', true);
                                } else {
                                    $api.setStorage('noNoticeWallet', false);
                                }
                                break
                        }

                    },
                    //立即升级
                    update() {
                        var vm = this;
                        //判断安卓还是ios android 去下载
                        if (api.systemType == "ios") {
                            //iOS安装：
                            api.installApp({
                                appUri: 'https://apps.apple.com/cn/app/id1556598283' //跳转到appstore下载
                            });
                        } else {
                            const resultList = api.hasPermission({
                                list: ['storage']
                            });
                            if (resultList[0].granted) {
                                vm.downLoadApk()
                            } else {
                                api.requestPermission({
                                    list: ['storage'],
                                }, function (ret, err) {
                                    if (ret && ret.list && ret.list.length > 0 && ret
                                        .list[0].granted) {
                                        vm.downLoadApk()
                                    }
                                });
                            }
                        }
                    },

                    //下载安卓apk
                    downLoadApk() {
                        var vm = this;
                        var timestamp = new Date().getTime()
                        var downLoadPath = `fs://tiexie${vm.newVersionCode}.apk`
                        //android下载并安装
                        api.download({
                            url: vm.androidDownloadUrl,
                            savePath: downLoadPath,
                            report: true,
                            cache: true,
                            allowResume: true
                        }, function (ret, err) {
                            if (ret.state == 0) {//下载中
                                //toastBottom("下载中，请稍后！")
                                vm.downLoadPercent = ret.percent
                            } else if (ret.state == 1) {
                                //下载成功 执行安装
                                api.installApp({
                                    appUri: ret.savePath
                                });
                            } else if (ret.state == 2) {
                                toastBottom("下载失败")
                            }
                        });
                    },
                    /**
                     *  融资保险名称+版本更新数据获取
                     */
                    getSystemSet() {
                        var vm = this;
                        common('getSystemSet')({}, function (ret) {
                            //是否显示邀请弹窗
                            var isNoNoticFlag = $api.getStorage('noNoticeWallet')
                            if (isNoNoticFlag) {
                                vm.showWalletPop = false;
                            } else {
                                //审核版本号与当前版本号相等 则隐藏活动入口
                                if (api.appVersion === ret.data.appModifyVersion) {
                                    vm.showWalletPop = false
                                } else {
                                    vm.showWalletPop = ret.data.onlineBonusEnabled
                                }
                            }

                            //是否显示看视频领红包入口
                            // if (api.appVersion != ret.data.appModifyVersion && ret.data.onlineWalletEnabled) {
                            //     vm.showVideoPop = true
                            // } else {
                            //     vm.showVideoPop = false
                            // }

                            //版本更新逻辑
                            vm.appVersionUpdate = ret.data.appVersionUpdate
                            vm.updateContent = ret.data.appDesc
                            vm.updateContent = vm.updateContent.replace(/\|/g, "\n")
                            vm.newVersionCode = ret.data.appVersion
                            let newVersion = ret.data.appVersion
                            let currentVersion = api.appVersion
                            newVersion = newVersion.split(".")
                            currentVersion = currentVersion.split(".")

                            let noNoticeVersion = $api.getStorage('noNoticeVersion')

                            //是否点击了不在提示
                            if (ret.data.appVersion == noNoticeVersion) {
                                vm.showUpdatePop = false
                            } else {
                                //比较三位版本号
                                if (api.systemType == "ios" && !vm.appVersionUpdate) {
                                    vm.showUpdatePop = false
                                } else {
                                    if (newVersion[0] > currentVersion[0]) {
                                        vm.showUpdatePop = true
                                    } else {
                                        if (newVersion[1] > currentVersion[1]) {
                                            vm.showUpdatePop = true
                                        } else {
                                            if (newVersion[2] > currentVersion[2]) {
                                                vm.showUpdatePop = true
                                            }
                                        }
                                    }
                                }
                            }
                            //融资保险名称
                            // vm.iconList1[2].name = ret.data.insuranceName || '三方服务'
                        })
                    },
                    //头条详情
                    goHeadLine() {
                        var vm = this
                        if (vm.headLineList.length > 0) {
                            api.openWin({
                                name: 'web_win',
                                url: '../web/web_win.html',
                                bounces: false,
                                pageParam: {
                                    url: vm.headLineList[0].url
                                }
                            });
                        }

                    },
                    // 打开外链
                    goWeb(banner) {
                        if (banner.targetType == 0) {//跳商品详情
                            api.openWin({
                                name: 'goods_detail_win',
                                url: '../whole_sale/goods_detail_win.html',
                                bounces: false,
                                pageParam: {
                                    id: banner.target,
                                    from: 'banner'
                                }
                            });
                        } else if (banner.targetType == 1) {//跳H5页面
                            api.openWin({
                                name: 'web_win',
                                url: '../web/web_win.html',
                                bounces: false,
                                pageParam: {
                                    url: banner.target
                                }
                            });
                        } else if (banner.targetType == 3) {//跳转到全民经纪人详情
                            this.goWalletDetail()
                        }
                    },
                    // 初始化 banner 视频秀
                    initData() {
                        var vm = this;
                        fnGet(interfaces.PRODUCT_MODULE.INDEX.GET_INDEXDATA, {}, false,
                            function (ret, err) {
                                console.log('视频秀:', JSON.stringify(ret));
                                if (ret && ret.code === RESPONSE_OK) {
                                    vm.banners = ret.data.banners;
                                    if (vm.banners) {
                                        vm.banners.map(item => {
                                            if (item.videoId) {
                                                common("getVideoPlay")(item.videoId, (ret) => {
                                                    var videoId = ret.data.videoBase.videoId
                                                    var index = vm.banners.findIndex(
                                                        target => {
                                                            return target.videoId == videoId
                                                        })
                                                    vm.$set(vm.banners[index], 'playURL',
                                                        ret.data.playInfoList[0].playURL
                                                    )
                                                })
                                            }
                                        })
                                    }
                                    vm.videoShow = ret.data.indexVideo;
                                } else
                                    toastBottom(ret ? ret.msg : '');
                            }
                        );
                    },
                    // 初始化头条
                    getHeadLineData() {
                        var vm = this;
                        fnGet(interfaces.CONTENT_MODULE.HOME.GET_HEADLINE_LIST, vm.queryHeadLine, false,
                            function (ret, err) {
                                console.log('头条:', JSON.stringify(ret));
                                if (ret && ret.code === RESPONSE_OK) {
                                    vm.headLineList = ret.data.list
                                } else {
                                    toastBottom(ret ? ret.msg : '');
                                }
                            }
                        );
                    },
                    // 初始化推荐视频
                    getRecommendVideo() {
                        var vm = this;
                        fnGet(interfaces.CONTENT_MODULE.HOME.GET_RECOMMEND_VIDEO, {}, false,
                            function (ret, err) {
                                console.log('推荐视频:', JSON.stringify(ret));
                                if (ret && ret.code === RESPONSE_OK) {
                                    vm.goodVideo = ret.data.topic
                                } else {
                                    toastBottom(ret ? ret.msg : '');
                                }
                            }
                        );
                    },
                    //底部推荐改变时
                    recommendChange() {
                        this.queryParams.types = this.recommendCategoryList[this.active].types;
                        this.queryParams.pageNum = 1;
                        this.getNew();
                    },
                    // 新品推荐
                    getNew() {
                        var vm = this
                        index.product("getListProducts")(vm.queryParams, function (ret) {
                            if (vm.queryParams.pageNum == 1) {
                                vm.listNew = []
                                vm.listNew = ret.data.list
                            } else {
                                vm.listNew = vm.listNew.concat(ret.data.list)
                            }
                            vm.hasNext = ret.data.hasNext
                        })
                    },

                    goPage(url, options) {
                        const myLocation = api.getPrefs({
                            sync: true,
                            key: 'location_home'
                        })
                        api.openWin({
                            name: url + '_win',
                            url: `../${url}/${url}_win.html`,
                            bounces: false,
                            pageParam: (options || {})
                        });
                        if (myLocation) {
                            api.openWin({
                                name: url + '_win',
                                url: `../${url}/${url}_win.html`,
                                bounces: false,
                                pageParam: (options || {})
                            });
                        } else {
                            this.checkLocation(url, options)
                        }
                    },

                    goDetail(item) {
                        var title = ''
                        if (item.type == 0) {
                            title = "SELL_DEVICE"
                        } else if (item.type == 2) {
                            title = "PARTS"
                        } else {
                            title = "LEASE_DEVICE"
                        }
                        api.openWin({
                            name: 'goods_detail_win',
                            url: "../whole_sale/goods_detail_win.html",
                            bounces: false,
                            pageParam: {
                                detailItem: item,
                                title: title
                            }
                        })
                    },

                },
            })
            api.setRefreshHeaderInfo({
                bgColor: '#f7f7f7',
                textDown: '下拉更新有惊喜',
                textUp: '松开可以刷新'
            }, function (ret, err) {
                vm.initData();
                vm.getHeadLineData();
                vm.getRecommendVideo();
                vm.newsForm.pageNum = 1
                vm.getNewsData();

                vm.isRefresh = true
                api.refreshHeaderLoadDone()
            });
            // 上拉加载
            api.addEventListener({
                name: 'scrolltobottom',
                extra: {
                    threshold: -10
                }
            }, function (ret, err) {
                // if (vm.hasNext) {
                //     vm.newsForm.pageNum = 1
                //     vm.getNewsData();
                // }
            });

            api.addEventListener({
                name: 'selectedCity'
            }, function (ret, err) {
                vm.selectedCityName = ret.value.city.name;
            });

            api.addEventListener({
                name: 'showLocation'
            }, function (ret, err) {
                vm.selectedCityName = ret.value.cityName;
            });
            api.addEventListener({
                name: 'refreshUnReadMessageNum'
            }, function (ret, err) {
                if (!ret.value.page || ret.value.page === 'home') {
                    vm.getUnReadNum()
                }
            });
        }
    </script>
</body>

</html>